<?php
include "includes/sesiones.php";
include "includes/comunes.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "includes/metas.php";?>
<link type="text/css" rel="Stylesheet" href="validar/jquery.validity.css" />
<script languaje='javascript' type='text/javascript'>
function confirmar(){

         var seleccion = confirm("Esta seguro que desea confirmar el credito cargado?");

if (seleccion)
 document.form.submit();
else
return seleccion;

        }
    </script>
<script language="JavaScript" type="text/javascript" src="combos/jquery.js"></script>

<script type="text/javascript" src="validar/jquery-1.6.4.min.js"></script>


<script language="JavaScript" type="text/javascript" src="combos/jquery.chainedSelects.js"></script>



<script language="JavaScript" type="text/javascript">
$(function()
{
	$('#financiera').chainSelect('#plan','combobox.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        $('#plan').chainSelect('#tasas','combobox.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});

});
</script>

<script type="text/javascript" src="validar/jquery.validity.min.js"></script>
<script type="text/javascript">
            $(function() {
                $("form").validity(function() {
                    $("#financiera")
                    .require("Seleccione una Financiera")
                    .match("integer","Seleccione una Financiera"),
                    $("#plan").require("Ingrese un Plan")
                    $("#tasas").require("Ingrese una Tasa")
                    $("#cuotas")
                    .greaterThanOrEqualTo(0.1, "Ingrese un Valor mayor a 0")
                    $("#monto").require("Ingrese un monto")
                    .greaterThanOrEqualTo(0.1, "Ingrese un Valor mayor a 0")




                });
            });
        </script>

<script type="text/javascript">
function pasardatos(){
var pos =document.getElementById('tasas').options.selectedIndex;
var datoseleccionado = document.getElementById('tasas').options[pos].text.split(",").join(".");
document.getElementById("valtasas").value=datoseleccionado;
//separo los valore
var elementos=document.getElementById('tasas').options[pos].value.split("_");

document.getElementById("cuotas").value=elementos[1];
document.getElementById("gracia").value=elementos[2];
document.getElementById("descuenta").value=elementos[3];
}
</script>


<style>
#loading
{
	position:absolute;
	top:0px;
	right:0px;
	background:#ff0000;
	color:#fff;
	font-size:14px;
	font-familly:Arial;
	padding:2px;
	display:none;
}
</style>
</head>

<body>
<div class="contenedor">
    <div id="loading">abriendo ...</div>
	<div class="cont">
    	<?php include "includes/head.php";?>
        <?php include "includes/menu.php";?>
            
    	<div class="novedadescont">
             <form id="form" name="form" method="post" action="grabarcredito.php">
        	<div class="novedadestitulo">
            	<div class="menuvolver"> <a href="javascript:history.back(1)">Volver Atrás</a></div>
            </div>
                 <div class="novedadestitulo">
            	<div class="novetitulo2">Alta de Creditos</div>
            </div>
            <div class="formucont">
                
           	  <div class="formlinea">

                <div class="formtxt">Nombre</div>
                <div class="formtxt2">
                    <label for="form"></label>
                    <input name="nombre" id="nombre" type="text"  value="<?php echo $_SESSION['clinombre'] ?>" disabled size="25" />
                  
                </div>
                
                </div>   
                
              <div class="formlinea">
                <div class="formtxt">Apellido</div>
                <div class="formtxt2">
                 
                    <label for="form"></label>
                    <input name="apellido" id="apellido" type="text"  value="<?php echo $_SESSION['cliapellido'] ?>" disabled size="25" />
                 
                </div>
                
                </div>
                
                
                
              <div class="formlinea">
                <div class="formtxt">Nº DNI</div>
                <div class="formtxt2">
                 
                    <label for="form"></label>
                    <input name="dni" id="dni" type="text" size="25" value="<?php echo $_SESSION['clidni'] ?>" disabled />
                  
                </div>
                
                </div>
            
		
                         
            </div>           
            <div class="novedadestitulo">
            	<div class="novetitulo2">Datos del Credito</div>
            </div>
           <div class="formlinea">
                <div class="formtxt">Entidad Financiera</div>
                <div class="formtxt2">

                    <label for="form"></label>
                    <select name="financiera" id="financiera">
                        <option selected value="seleccionar">Seleccionar</option>
                        <?php
                        $sqlfin="select  * from TipoCreditos order by id desc";
                        $resfin= cons_ins($sqlfin);
                        while ($regdet=mysql_fetch_array($resfin)){
                            echo "<option value='".$regdet['id']."'>".trim(utf8_encode($regdet['Nombre']))."</option>";
                            
                         }

                        ?>
                    </select>
        
                </div>

                </div>
				<div class="formlinea">
                <div class="formtxt"></div>
                <div class="formtxt2">
                </div>
                            </div>
             <div class="formlinea">
                <div class="formtxt">Plan</div>
                <div class="formtxt2">

                <select name="plan" id="plan" style="display:none">
                    </select>

                </div>

                </div>
				
				<div class="formlinea">
                <div class="formtxt"></div>
                <div class="formtxt2">
                </div>
</div>
              <div class="formlinea">
                <div class="formtxt">Tasa</div>
                <div class="formtxt2">

                    <label for="form"></label>
                     <select name="tasas" id="tasas" style="display:none" onChange="pasardatos()">
                    </select>
               <input name="valtasas" id="valtasas" type="hidden" />
               <input name="descuenta" id="descuenta" type="hidden" />
                </div>

                </div>

               <div class="formlinea">
                <div class="formtxt">Amortizacion</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="amortizacion" id="amortizacion" type="text" size="25" value="Simple" disabled />


                </div>

                </div>

                 <div class="formlinea">
                <div class="formtxt">Autorizacion</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="autorizacion" id="autorizacion" type="text" size="25" />


                </div>

                </div>
                   <div class="formlinea">
                <div class="formtxt">Gracia</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="gracia" id="gracia" type="text" size="25" value="0" />


                </div>

                </div>

                  <div class="formlinea">
                <div class="formtxt">Cuotas</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="cuotas" id="cuotas" type="text" size="25" />


                </div>

                </div>

                  <div class="formlinea">
                <div class="formtxt">Monto</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="monto" id="monto" type="text" size="25" />


                </div>

                </div>

                 <div class="formlinea">
                <div class="formtxt">Dia Vto</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="diavto" id="diavto" type="text" size="25" value="15"/>


                </div>

                </div>
				
				<div class="formlinea">
                <div class="formtxt">Entrega</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="entrega" id="entrega" type="number" step="0.1" size="25" value="0"/>


                </div>

                </div>

                  <div class="formlinea">
                <div class="formtxt">Observacion</div>
                <div class="formtxt2">

                    <label for="form"></label>
                   <input name="observacion" id="observacion" type="text" size="30" />


                </div>

                </div>
            <div class="formlinea">
                <div class="formtxt"></div>
                <div class="formtxt2">
                <input id="Button1" type="button" onclick="LlenarFila();" value="Calcular Cuotas"/>
               </div>
                 </div>
          <div class="novedadestitulo">
            	<div class="novetitulo2">Detalle de cuotas</div>
            </div>
  <table cellspacing="0" cellpadding="4" border="0" id="tblTabla"  style="color: #333333;
        width: 100%; border-collapse: collapse;">
        <tr style="color:#000; font-weight: bold;font-family: Tahoma; background-color:#666;">
            <th align="left">
                Nro
            </th>
            <th align="center">
                Fecha. Vto.
            </th>
             <th align="center">
                Capital
            </th>
            <th align="center" scope="col">
                Interes
            </th>
              <th align="center" scope="col">
                Total Cuota
            </th>
        </tr>
    </table>



             <table style="color: #333333; width: 100%">
                 <tr><td><input id="Button1" type="button"  onclick="confirmar();"  value="Grabar Credito"/></td></tr>
             </table>

        	<div class="novedadesbottom"></div>
                </form>
        </div>
    
    
    
    
    <div class="separador"></div>
<?php include "includes/menufooter.php";?>
    
	<div id="clearing"></div>    
    </div>
<div id="clearing"></div>

 
</div>
    <script language="javascript" type="text/javascript">
        function LlenarFila() {
            //Iniciamos esta linea para que el Jquery no tenga conflicto con otras librerias que tengas
            jQuery.noConflict();

            //Capturamos el Numero de filas en la variable
            var NroFila = document.getElementById("cuotas").value;
            var Gracia = document.getElementById("gracia").value;
            var Capital = document.getElementById("monto").value / (NroFila-Gracia) ;
            var Entrega=document.getElementById("entrega").value;
            //obtengo el valor del interes
            var posicion =document.getElementById('tasas').options.selectedIndex;
            var Int = document.getElementById('tasas').options[posicion].text.split(",").join(".");
            var Interes = parseFloat(Int)*parseFloat(Capital);

            //tratamos la fecha
            var dia=document.getElementById("diavto").value
            var f = new Date();
            var mes=f.getMonth()+parseInt(1);
            var ano=f.getFullYear();
			
            

            var Total = parseFloat(Interes) + parseFloat(Capital) ;
            //removemos las filas que pueda tener la tabla
            jQuery('#tblTabla tr').next().remove();
            
			if(document.getElementById("entrega").value>0){
			inicial=2;
			jQuery('#tblTabla tr:last').after('<tr>' +
                '<td align="left" style="font-family: Tahoma;">1</td>' +
                  '<td align="center" style="font-family: Tahoma;">'+ f.getDate() +'/' + mes + '/' + ano + '</td>' +
                  '<td align="center" style="font-family: Tahoma;">$' + Entrega + '</td>' +
                '<td align="center" style="font-family: Tahoma;">$ 0.00</td>' +
                '<td align="center" style="font-family: Tahoma;">$ ' + Entrega + '</td></tr>');
			NroFila=parseInt(NroFila)+parseInt(1);
			
			}else{
			inicial=1;}
			
			var mes=f.getMonth()+parseInt(2);
            //Recorremos el NroFila y vamos creando las filas
            for (var x = inicial; x <= NroFila; x++) {

             
                if(x<=Gracia){
                   jQuery('#tblTabla tr:last').after('<tr>' +
                '<td align="left" style="font-family: Tahoma;">' + x + '</td>' +
                  '<td align="center" style="font-family: Tahoma;">'+ dia +'/' + mes + '/' + ano + '</td>' +
                  '<td align="center" style="font-family: Tahoma;">$ 0.00</td>' +
                '<td align="center" style="font-family: Tahoma;">$ 0.00</td>' +
                '<td align="center" style="font-family: Tahoma;">$ 0.00</td></tr>');
                }else{
                jQuery('#tblTabla tr:last').after('<tr>' +
                '<td align="left" style="font-family: Tahoma;">' + x + '</td>' +
                  '<td align="center" style="font-family: Tahoma;">'+ dia +'/' + mes + '/' + ano + '</td>' +
                  '<td align="center" style="font-family: Tahoma;">$ ' + Capital.toFixed(2) + '</td>' +
                '<td align="center" style="font-family: Tahoma;">$ ' + Interes.toFixed(2) + '</td>' +
                '<td align="center" style="font-family: Tahoma;">$ ' + Total.toFixed(2) + '</td></tr>');}

                    if(mes==12){
                        mes=1;
                        ano=parseInt(ano)+1
                    }else
                        {
                         mes=parseInt(mes)+1
                        }

             

            }
            //Colocamos algo de extra para colorear las filas :P
            jQuery('#tblTabla tr:odd').css('background-color', '#E9F0F8');
            
        }
    </script>
</body>
</html>
